﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using JXT.PrimaryKey.Batman.Core.Configuration;

namespace JXT.PrimaryKey.Batman.Core.OAuth
{
    /// <summary>
    /// OAuth认证上下文对象
    /// </summary>
    public class AuthContext
    {
        /// <summary>
        /// 应用key
        /// </summary>
        public string AppKey { get; private set; }

        /// <summary>
        /// 签名key
        /// </summary>
        public string SignatureKey { get; private set; }

        /// <summary>
        /// token
        /// </summary>
        public string Token { get; internal set; }

        /// <summary>
        /// tokensecret
        /// </summary>
        public string TokenSecret { get; internal set; }

        /// <summary>
        /// verifier
        /// </summary>
        public string Verifier { get; internal set; }

        /// <summary>
        /// 认证用户Id
        /// </summary>
        public string UserId { get; internal set; }

        public AuthContext()
        {
        }

        public AuthContext(string appKey, string signatureKey)
        {
            var configurationSection = SupernovaConfigurationManager.GetServiceConfigurationSection();
            if (configurationSection != null)
            {
                if (String.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(signatureKey))
                {
                    appKey = configurationSection.OauthSetting.DefaultAppKey;
                    signatureKey = configurationSection.OauthSetting.DefaultAppSecret;
                }
            }
            AppKey = appKey;
            SignatureKey = signatureKey;
        }
    }
}
